package cn.zktr.Personnel.controllers.tantiantian;


import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.zktr.Personnel.model.pojos.PerPmsEmp;
import cn.zktr.Personnel.model.pojos.PerTngPlan;
import cn.zktr.Personnel.model.service.tantiantian.SlySetService;
import cn.zktr.Personnel.model.service.tantiantian.TngPlanService;
import cn.zktr.Personnel.model.service.zhouyongcong.findService;
import cn.zktr.Personnel.model.uitls.Homapape;

@Controller
public class TngPlanController {
	/**
	 * 培训计划
	 */
	@Autowired
	private TngPlanService planser;
	/**
	 * 薪资套帐
	 */
	@Autowired
	private SlySetService slyser;
	
	/**
	 * 员工
	 */
	@Autowired
	private findService findser;
	//培训计划
	@RequestMapping("ttt/training-plan")
	public void TrainingPlan(HttpSession session){
		//查询所有培训部长
		JSONArray Plan = planser.selePlan(session);
		session.setAttribute("Plan",Plan);
	}
	@RequestMapping("TrainingPlantables")
	@ResponseBody
	public Map<String,Object> TrainingPlantable(int page,int rows,HttpSession session){
		//查询所有培训部长
		JSONArray Plan = planser.selePlan(session);
		session.setAttribute("Plan",Plan);
		
		Map<String,Object> map = new HashMap<>();
		map.put("total",planser.selePlanAll().size());
		Page<Object> p=PageHelper.startPage(page,rows);
		JSONArray findAll=planser.selePlanAll();
		//页内容
		map.put("rows",findAll);
		return map;
	}
	@RequestMapping("add_plan")
	@ResponseBody
	public void add_plan(
			PerTngPlan plan,
			String planninds,
			String planmaxds,
			Integer shenpiren,
			HttpSession session
		){
		//创建人
		plan.setPerPmsEmp1(findser.findEmpid(Integer.valueOf(session.getAttribute("id")+"")));
		//审批人
		PerPmsEmp emp = slyser.seleEmpids(shenpiren);
		plan.setPerPmsEmp2(emp);
		
		//状态
		plan.setPlanstate("0");
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Timestamp ts1 = new Timestamp(format.parse(planninds).getTime());
			plan.setPlannind(ts1);
			Timestamp ts2 = new Timestamp(format.parse(planmaxds).getTime());
			plan.setPlanmaxd(ts2);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		planser.AddPlan(plan);
	}
	@RequestMapping("tupdate_plan")
	@ResponseBody
	public void tupdate_plan(
			PerTngPlan plan,
			String planninds,
			String planmaxds,
			Integer shenpiren,
			HttpSession session
		){
		planser.tupdate_plan(plan,planninds,planmaxds,shenpiren,session);
	}
	//我的培训
	@RequestMapping("ttt/my-peixun")
	public void peixun(){
				
	}
	//培训计划送审plan_songshen
	@RequestMapping("plan_songshen")
	@ResponseBody
	public void plan_songshen(
			Integer planid,HttpSession session){
		planser.plan_songshen(planid,session);
	}
	@RequestMapping("TrainingPlantables_name")
	@ResponseBody
	public JSONArray TrainingPlantables_name(String text){
		return planser.TrainingPlantables_name(text);
	}
	
}
